package com.jwork.progress.controllers;

import com.jwork.progress.config.annotation.SubmitToken;
import com.jwork.progress.params.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping(value = "/api")
public class SubmitTokenController {
    private static final Integer EXPIRE_TIME = 60;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @PostMapping("getSubmitToken")
    public CommonResponse getToken() {
        String uuid = UUID.randomUUID().toString();
        stringRedisTemplate.opsForValue().set(uuid, uuid, EXPIRE_TIME, TimeUnit.SECONDS);

        return CommonResponse.success(uuid);
    }

    @SubmitToken
    @PostMapping("orderConfirm")
    public CommonResponse orderConfirm() throws InterruptedException {
        return CommonResponse.success("成功");
    }
}
